package com.lxl.todo;

//package com.lxl.



/**
 * 双指针问题
 * url https://leetcode.cn/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-100-liked
 * 给定一个长度为 n 的整数数组 height 。有 n 条垂线，第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。
 *
 * 找出其中的两条线，使得它们与 x 轴共同构成的容器可以容纳最多的水。
 *
 * 返回容器可以储存的最大水量。
 */

public class Solution4 {
    public int maxArea(int[] height) {
        int n = height.length,left = 0,right = n-1;
        int max = 0;
        for (int i = 0; i < height.length; i++) {
            while(left < right){
                int area = (right-left) * Math.min(height[left], height[right]);
                if(height[left] <= height[right]) {
                    left++;
                }else {
                    right--;
                }
                max = Math.max(max, area);
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        int[] nums2 = {1, 1};
        Solution4 solution4 = new Solution4();
        int i = solution4.maxArea(nums);
        int z = solution4.maxArea(nums2);
        System.out.println("i = " + i);
        System.out.println("z = " + z);
    }
}
